<template>
	<div>
		<!-- <so-header :seller="headerTitle"></so-header> -->
    <setHeader :title="headerTitle"></setHeader>
    <div class="pagecontent">
        <h3 class="mt-notice" style="color: #e50838 !important; text-align: left !important;padding: 0 0.2rem !important;">欢迎您成为该企业管理员</h3>
        <div class="write_input_box write-label">
            <label for="">企业名称：</label>
            <input type="text" placeholder="请输入企业名称" v-model="companyName" @mousedown="showPicker">
        </div>
        <div class="write_input_box write-label" @click.capture="selectIndustry">
            <label for="">所在行业：</label>
            <span v-if="hy_name">
              {{hy_name}}
            </span>
            <span v-else style="font-size: 0.26rem; color: #ededed;line-height:0.3rem;">
              请选择行业
            </span>
            <!-- <input type="text" placeholder="请选择行业" v-model="hy_name" @mousedown="showPicker"  @click.capture="selectIndustry"> -->
        </div>
        <div class="write_input_box write-label">
            <label for="" style="width: 1.8rem;">管理人姓名：</label>
            <input type="text" placeholder="请输入您的真实姓名" v-model="userInfo.username">
        </div>
        <div class="write_input_box write-label" style="border-bottom: none;">
            <label for="" style="width: 1.8rem;">管理人职位：</label>
            <input type="text" placeholder="请输入管理人的职位" v-model="tel">
        </div>
        <div class="btn_big_red" @click="NextStep" style="margin-top: 0.9rem;">
            <button>确认</button>
        </div>
    </div>
    <!-- 行业 -->
    <IndustryLinkage v-show="industryShow" @categoryname="showIndustry" @categoryId="showIndustryId" @done="closeAdd" :industryshow="true"></IndustryLinkage>


		<!-- <mt-field label="企业名称：" placeholder="请输入圈子名称"  v-model="companyName" @mousedown.native="showPicker"></mt-field>
    <mt-field label="管理员姓名：" placeholder="请输入管理员姓名"  v-model="userInfo.username"></mt-field>
   
    <mt-field label="管理员职位：" placeholder="请输入您的职位"  v-model="tel"></mt-field>
		<mt-button type="default" class="el-long-button el-long-create-button y-btn-red "  @click="NextStep">创建企业</mt-button> -->

     <!-- <mt-popup
        v-model="popupVisibleIndustry"
        position="bottom">
      <ul> 
        <li v-for="list in IndustryList" @click="selectpIndustry(list.HY_KEY,list.id,list.HY_MC)" :key="list.id">{{list.HY_MC}}</li>
      </ul>
    </mt-popup> -->
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import { MessageBox } from 'mint-ui';
import IndustryLinkage from '@/components/industry_linkage';


export default {
	data() {
      return {
        headerTitle:'企业资料',
        industryShow: false,
        companyName: '',
        userInfo:'',
        tel:'',
        trade:'',
        popupVisibleIndustry:false,
        IndustryList:[],
        hy_name:'',
        c_hyId:'',
      };
    },
    components: {
      setHeader,
      IndustryLinkage
    },
    created() {
      let that = this;
      that.userInfo = window.localStorage.getItem('userInfo');
      that.userInfo = JSON.parse(that.userInfo);
      //初始化 获取一级行业
			// that.getIndustryList(0,'','');

    },
    mounted() {
      // let that = this;
      // var user = Promise.resolve(this.getUserInfo())
      // user.then(
      //   function (result) { 
      //   // console.log(result);
      //   that.userInfo = result;
      // })
      this.companyName = this.$route.query.companyName;
    },
    methods:{
       /******行业**************/
			//获取行业列表
			// getIndustryList(pkey,id,hy_name){
			// 	// let pkey = 0;
			// 		this.$fetch(this.$path + '/api.php/circle/getIndustryList',{pkey}).then((response) => {
			// 			console.log('行业列表', response); 
			// 			if(response){
			// 				if(response.code == 200) {
			// 						this.IndustryList = response.data;
			// 				}else{
			// 					console.log('数据错误');
			// 				}
			// 			}else{
			// 				console.log(id);
			// 				this.industryId = id;
      //         this.trade = id;
      //         this.hy_name = hy_name;
			// 				this.popupVisibleIndustry = false;

			// 			}
						
      //     })
			// },
			//点击选择父级行业
			// selectpIndustry(val,id,name){
			// 		this.getIndustryList(val,id,name);
      // },
      
			//点击选择行业
      selectIndustry:function(){
				//console.log(9898);
				// this.getIndustryList(0,'','');
				// this.popupVisibleIndustry = true;
				this.industryShow = !this.industryShow;
      },
      //选择行业
      showIndustry(data) {
        this.hy_name = data;
        this.industryShow = false;
      },
      // 选择好后关闭行业
      showIndustryId(data) {
        this.c_hyId = data;
        console.log('行业Id',this.c_hyId);
        this.industryShow = false;
      },
      // 关闭选择地区
      closeAdd() {
        this.linkShow = false;
        this.industryShow = false;
      },
      
    	NextStep:function(){
    		let that = this;
    		let companyName = that.companyName;
        let job = that.tel;
        let adminName = that.userInfo.username;
        let userId = that.userInfo.uid;
        let trade = that.c_hyId;
        let access_token = window.localStorage.getItem('access_token');
        // console.log(trueName);
        if(adminName == '' || adminName == undefined){
          MessageBox('温馨提示', '请输入您的姓名');
          return false;
        }
    		if(job == '' || job == undefined){
    			MessageBox('温馨提示', '请输入您的职位');
          return false;
    		}else{

      		//提交创建企业
          that.$fetch(that.$path + '/api.php/company/userCreateCompany', {companyName,adminName,job,userId, access_token,trade}).then((response) => {
            if(response.code != 200){
              MessageBox.alert( response.msg).then(action => {

                if(response.code == 2007){
                  that.$router.push({path: '/Certification', query: {companyId: 1,companyName: companyName}})
                }
              });
              return false;
            }else{



              // 如果没有默认企业则默认选择第一个企业
              that.userInfo = window.localStorage.getItem('userInfo');
              that.userInfo = JSON.parse(that.userInfo);
              if(!that.userInfo.company){
                that.userInfo.position     = response.data.company.position;    //职位
                that.userInfo.industry     = response.data.company.industry;    //行业
                that.userInfo.company      = response.data.c_id;                //默认企业id
                let userInfo = JSON.stringify(that.userInfo);
                window.localStorage.setItem('userInfo',userInfo);
              }

              that.$router.replace({path: '/createSuccess', query: {companyId: 1,companyName: companyName}})
            } 
          })	
      	}
    	},
      
      showPicker(e){
        e.preventDefault(); //阻止输入法的唤醒
      },
     
    }
}

</script>

<style>
.el-long-create-button{
	margin-top:50px;
}

/* #app{
  background:rgba(244,245,247,1);
} */
/*返回按钮*/
/* .mint-header .mint-button {
    background-color: transparent;
    border: 0;
    -webkit-box-shadow: none;
    box-shadow: none;
    color: inherit;
    display: inline-block;
    padding: 0;
    font-size: inherit;
    display: block;
  } */
  .mintui{
    font-size: 0.36rem;
  }
  /* 头部颜色透明 */
/* .mint-header{
  background-color: #fff !important;
}
.mint-header-title{
  overflow: visible ;
   color: #333333 ;
   font-size: 0.36rem ;
    font-family:SourceHanSansCN-Medium;
    font-weight:500;
    color:rgba(51,51,51,1);
    line-height: 0.36rem ;
}
a:-webkit-any-link{
  color:  #333333 ;
  font-size: 0.36rem ;
} */
  /* 隐藏右边功能键 */
  /* .is-right{
    opacity: 0;
  } */
   .mint-cell-wrapper{
   padding-left:   0.3rem ;
   height: 0.94rem  ;
   /* margin-top: 0.2rem ; */
 }
 .mint-field-core{
   font-size: 0.28rem ;
   color: #C6C6C6 ;
 }

/* 数据库不存在该企业 */
 .mt-notice{
   /* height: 1.1rem ; */
   line-height: 1.1rem ;
   font-size: 0.36rem ;
   padding: 0 0.2rem ;
   font-weight: 500;
   font-family:SourceHanSansCN-Medium;
 }
 .mint-cell-title{
   color: #333333 ;
   font-size: 0.28rem ;
 }
 .mint-cell-title {
    width: 2rem !important;
}
.y-btn-red{
  margin-top: 0.9rem ;
}

/* 创建企业 */

.write-label input {
  width: 72% !important;
}
</style>